<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('学生测评列表')"/>
    <th:block th:include="include :: summernote-css"/>
    <th:block th:include="include :: select2-css"/>
    <th:block th:include="include :: bootstrap-select-css"/>
    <th:block th:include="include :: datetimepicker-css"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="notice-form">
                <div class="select-list">
                    <ul>
                        <input id="childId" name="childId" type="hidden" th:value="${childId}"/>
                        <li>
                            测评编号：<input type="text" name="evaluateNumber"/>
                        </li>
                        <li class="select-time">
                            <label style="width: 80px">测评时间：</label>
                            <input type="text" class="time-input" id="beginTime" placeholder="开始时间" name="beginTime"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="endTime"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: summernote-js"/>
<th:block th:include="include :: select2-js"/>
<th:block th:include="include :: bootstrap-select-js"/>
<th:block th:include="include :: datetimepicker-js"/>
<script th:inline="javascript">
    // 权限
    var evaluateFlag = [[${@permission.hasPermi('business:evaluate:view')}]];
    var getReportFlag = [[${@permission.hasPermi('business:childReport:getReport')}]];
    var downloadReportFlag = [[${@permission.hasPermi('business:childReport:download')}]];

    // 字典
    var evaluateStatus = [[${@dict.getType('business_evaluate_status')}]];
    var prefix = ctx + "business/childReport";

    $(function () {
        var options = {
            url: prefix + "/findChildReportList",
            modalName: "数据",
            queryParams: queryParams,
            columns: [{
                checkbox: true
            },
                {
                    field: 'childName',
                    title: '学员姓名',
                },
                {
                    field: 'evaluateNumber',
                    title: '测评编号',
                },
                {
                    field: 'evaluateVersion',
                    title: '测评版本',
                },
                {
                    field: 'status',
                    title: '测评状态',
                    formatter: function (value, row, index) {
                        var actions = [];
                        $.each(evaluateStatus, function (index, dict) {
                            if (dict.dictValue == ('' + value)) {
                                var listClass = "label label-primary";
                                if (row.status == 0) {
                                    listClass = "label label-success";
                                } else if (row.status == '1') {
                                    listClass = "label label-primary";
                                } else if (row.status == '2') {
                                    listClass = "label label-warning";
                                }
                                actions.push($.common.sprintf("<span class='%s'>%s</span>", listClass, dict.dictLabel));
                                return false;
                            }
                        });
                        return actions.join('');
                    }
                },
                {
                    field: 'createTime',
                    title: '测评开始时间',
                },
                {
                    field: 'updateBy',
                    title: '最后维护人',
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + getReportFlag + '" href="javascript:void(0)" onclick="getReport(\'' + row.evaluateNumber + '\',\'' + row.childName + '\')"><i class="fa fa-search"></i>查看报告</a> ');
                        actions.push('<a class="btn btn-success btn-xs ' + downloadReportFlag + '" href="javascript:void(0)" onclick="downloadReport(\'' + row.evaluateNumber + '\')"><i class="fa fa-download"></i>下载</a> ');
                        if(row.trainingProgramNumber !=null && row.trainingProgramNumber!=''){
                            actions.push('<a class="btn btn-success btn-xs ' + downloadReportFlag + '" href="javascript:void(0)" onclick="viewTrainingProgram(\'' + row.childId + '\',\'' + row.evaluateNumber + '\')">训练计划预览</a> ');
                        }
                        return actions.join('');
                    }
                }
                ]
        };
        $.table.init(options);
    });

    function childEvaluate(evaluateNumber, childName) {
        var childId = $("#childId").val();
        var url = ctx + "business/childQuestion/getChildQuestion/" + childId + "?evaluateNumber=" + evaluateNumber;
        $.modal.openTab(childName + "的测评", url);
    }

    function getReport(evaluateNumber, childName) {
        var url = ctx + "business/childReport/reportTable/" + evaluateNumber;
        var options = {
            title: '查看报告',
            width: "600",
            url: url
        };
        // $.modal.openOptions(options);
        $.modal.openFull(childName + '的测评报告', url);
    }

    function downloadReport(evaluateNumber) {
        $.ajax({
            url: ctx + "business/childReport/getReportPdfUrl/" + evaluateNumber,
            type: "get",
            processData: false,
            contentType: false,
            success: function (result) {
                console.log(result)
                if (result.code == 500) {
                    $.modal.alertWarning(result.msg);
                } else {
                    openWin(result)
                }
            }
        })
    }
    function viewTrainingProgram(childId, evaluateNumber) {
        // $.ajax({
        //     url: ctx + "business/childReport/getReportPdfUrl/"+childId+"/"+evaluateNumber,
        //     type: "get",
        //     success: function(result) {
        //         if (result.code == 0) {
        //             var url = ctx + "business/childReport/childReport/" + childId;
        //             $.modal.openTab(childName + "的测评记录", url, 1200, null, null);
        //         }
        //     }
        // })
        var url = ctx + "business/learningReport/childTrainingProgram/" + childId+"/"+evaluateNumber;
        $.modal.openTab("训练计划", url, 1200, null, null);

    }

    function openWin(url) {
        $('body').append($('<a href="'+url+'" id="openWin" target="_blank"></a>'))
        document.getElementById("openWin").click();//点击事件
        $('#openWin').remove();
    };

    function queryParams(params) {
        var search = $.table.queryParams(params);
        var childId = $("#childId").val();
        search.childId = childId;
        return search;
    }


</script>
</body>

</html>